package com.vodone.v1pin.video.delegate
{
	import com.vodone.v1pin.video.view.vo.CommentVO;
	
	import mx.collections.ArrayCollection;

	public class CommentUtil
	{
		public static function getCommentListFromObj(obj:Object):ArrayCollection
		{
			var list:ArrayCollection = new ArrayCollection();
			if(obj && obj is Array)
			{
				var arr:Array = obj as Array;
				if(arr && arr.length > 0)
				{
					for(var i:int = 0; i< arr.length ; i++)
					{
						list.addItem(getCommentItem(arr[i]));
					}
				}
			}
			return list;
		}
		public static function getCommentItem(obj:Object):CommentVO
		{
			var item:CommentVO = new CommentVO();
			if(obj)
			{
				if(obj.hasOwnProperty("username"))
				{
					item.username = obj["username"];
				}
				if(obj.hasOwnProperty("comment"))
				{
					item.comment = obj["comment"];
				}
				if(obj.hasOwnProperty("stime"))
				{
					item.stime = obj["stime"];
				}
			}
			return item;
		}
		public static function deleteSampleData(list:Array , arr:Array):Array
		{
			if(list && arr && arr.length > 0 && list.length > 0)
			{
				for(var i:int = list.length - 1 ; i >= 0 ; i--)
				{
					for(var j:int = 0;j<arr.length ;j++)
					{
						if((list[i] as CommentVO).username==(arr[j] as CommentVO).username && 
							(list[i] as CommentVO).comment==(arr[j] as CommentVO).comment)
						{
							(arr[j] as CommentVO).stime = (list[i] as CommentVO).stime;
							list.splice(i,1);//删除重复的评论
							break;
						}
					}
				}
			}
			return list;
		}
	}
}